//
//  OtherDetailTitleCell.swift
//  ImGuider X
//
//  Created by llt on 2018/9/27.
//  Copyright © 2018 imguider. All rights reserved.
//

import UIKit


class OtherDetailTitleCell: UITableViewCell {
    
    
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var etitleLabel: UILabel!
    
    @IBOutlet weak var tagView: CustomTagView!
    
    @IBOutlet weak var introLabel: UILabel!
    
    @IBOutlet weak var gpsBtn: UIButton!
    
    @IBOutlet weak var gpsWidth: NSLayoutConstraint!
    
    var openMaps:(()->Void)?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        self.backgroundColor = kThemeBgColor
        
        gpsBtn.addShadow(type: .btn)
    }
    
    var calendar:Calendar? {
        
        didSet {
            
            guard let calendar = calendar else {
                
                return
            }
            
            titleLabel.text = calendar.title
            etitleLabel.text = calendar.etitle
            
            if calendar.coor != nil {
                
                gpsBtn.isHidden = false
                gpsWidth.constant = 40
            } else {
                
                gpsBtn.isHidden = true
                gpsWidth.constant = -5
            }
            
            
            let att = NSMutableAttributedString(string: calendar.intro ?? "")
            
            att.yy_font = kFont12
            att.yy_color = UIColor.hexStringToColor(hexString: "#222222")
            att.yy_lineSpacing = 8
            
            introLabel.attributedText = att
            
            if let tagArray = calendar.tagArray, tagArray.count > 0 {
                
                tagView.isHidden = false
                tagView.setTagArray(tagArray) { maker in
                    
                    let color = UIColor.hexStringToColor(hexString: "#707070")
                    
                    maker?.strokeColor = color
                    maker?.strokeWidth = 1.0
                    maker?.cornerRadius = 8
                    maker?.insets =  UIEdgeInsets(top: -1, left: -8, bottom: -1, right: -8)
                    maker?.font = kFont10
                    maker?.textColor = color
                    maker?.space = 8
                    maker?.linespace = 16
                    maker?.tagAlignment = .left
                }
            } else {
                
                tagView.tagViewH?.constant = 0
                tagView.isHidden = true
            }
        }
    }
    
    @IBAction func gpsAction(_ sender: Any) {
        
        self.openMaps?()
    }
}

